package pkg.chemdrm;

import org.anddev.andengine.entity.sprite.Sprite;
import org.anddev.andengine.opengl.texture.region.TextureRegion;

public class EntityFlask extends Sprite implements Entity 
{
	private final float ANGLE_VELOCITY = 720f; // two times a sec
	private final float LINE_VELOCITY = 256f;
	private final float MAX_LIFE = 32*6/LINE_VELOCITY;
	
	private boolean mExists 	= true;
	private float mDirection 	= 0;
	private float mLifetime 		= 0;
	
	
	public EntityFlask(float pDirection, float pX, float pY, float pWidth, float pHeight, TextureRegion pTextureRegion) 
	{
		super(pX, pY, pWidth, pHeight, pTextureRegion);
		mDirection = pDirection;
		System.out.println("new flaks, lifetime is " + MAX_LIFE);
	}

	public void update(float dt) 
	{
		// update animations and such
		mLifetime += dt;
		
		if(mLifetime >= MAX_LIFE)
		{
			detachSelf();
			mExists = false;
		}
		
		setRotation(ANGLE_VELOCITY*mLifetime);
		float x = (float) (getX() + LINE_VELOCITY*Math.cos(mDirection)*dt);
		float y = (float) (getY() + LINE_VELOCITY*Math.sin(mDirection)*dt); 
		
		setPosition(x, y);
	}

	public boolean getExists() 
	{
		return mExists;
	}
	
	public void destroySelf()
	{
		detachSelf();
		mExists = false;
		
	}
	
	
}
